/**
 * Copyright (c) 2011-2014, hubin (243194995@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.sakz.oss;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;


/**
 * <p>
 * 
 * @author hubin   
 * @date 2015年3月25日
 * @version 1.0.0
 */ 
@Controller    
public class IndexController {

    @RequestMapping(value = "/", method = {RequestMethod.GET,RequestMethod.POST})  
    public ModelAndView index(HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException {
    	String token=request.getParameter("token");
    	User user=new ObjectMapper().readValue(
    			request.getSession().getAttribute(SSOShiro.DEFAULT_KEY_ATTRIBUTE_NAME).toString(),User.class);
    	System.out.println("登录用户："+user.getUserName());
    	ModelAndView modelAndView=new ModelAndView("index");
    	modelAndView.addObject("token",token);
    	modelAndView.addObject("user",user);
        return modelAndView;
    }
    
    @RequestMapping(value = "/noperms", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String noperms(HttpServletRequest request) {
    	return "无访问权限";
    }
    @RequestMapping(value = "/status", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String status(HttpServletRequest request) {
    	return "您已经登录,正在使用admin权限";
    }
    
}